<!--
 * @Author: your name
 * @Date: 2020-07-28 11:52:33
 * @LastEditTime: 2020-08-11 10:23:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /website/src/pages/productList.vue
--> 
<template>
  <div>
    <div class="container">
      <div class="product-content">
        <left-side-bar :title="title" :contact="contact">
          <!-- <slot name="currentTitle"></slot> -->
          <template v-slot:currentTitle>
            <p>企业新闻</p>
            <p>公司新闻</p>
            <p>行业新闻</p>
          </template>
        </left-side-bar>
        <div class="product-content_right">
          <p class="current-position">
            <span>当前所在位置:</span>
            <span>
              首页
              <i class="icon-arrow">>>></i>
            </span>
            <span>{{title}}</span>
          </p>
          <div class="product-item">
            <el-form size="middle" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="ruleForm.name"></el-input>
              </el-form-item>
              <el-form-item label="邮箱" prop="mail">
                <el-input v-model="ruleForm.mail"></el-input>
              </el-form-item>
              <!-- <el-form-item label="电话" prop="phone">
                <el-input v-model="ruleForm.phone"></el-input>
              </el-form-item> -->
              <!-- <el-form-item label="地址" prop="address">
                <el-input v-model="ruleForm.address"></el-input>
              </el-form-item> -->
              <el-form-item label="留言内容" prop="content">
                <el-input :rows="6" type="textarea" v-model="ruleForm.content"></el-input>
              </el-form-item>
              <el-form-item :style="{textAlign: 'center'}">
                <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import LeftSideBar from '../components/LeftSideBar'

export default {
  name: 'comment',
  components: {
    LeftSideBar
  },
  data () {
    return {
      type: '',
      contact: {},
      title: '',
      ruleForm: {
        name: '',
        email: '',
        phone: '',
        address: '',
        content: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { message: '姓名不能为空', trigger: 'blur' }
        ],
        mail: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { message: '邮箱能为空', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { message: '电话不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入联系地址', trigger: 'blur' },
          { message: '联系地址不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入留言内容', trigger: 'blur' },
          { message: '留言内容不能为空', trigger: 'blur' }
        ],
      }
    }
  },
  mounted() {
    /* eslint-disable */
    this.title = this.$route.params.title || '联系我们'
    this.type = this.$route.query.type
    this.contact = JSON.parse(window.localStorage.getItem('homeData')).sysContact || {}
    console.log(this.contact)
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm)
          axios.post('/leavingmessage', Qs.stringify(this.ruleForm)).then(res => {
            if (res.msg.code === 1) {
              this.$message.success(res.msg.msg)
              this.$refs[formName].resetFields()
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .product-content{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin: 15px 0;
    .product-content_right{
      flex-grow: 1;
      margin-left: 35px;
      align-items: center;
      .current-position{
        padding: 5px 0;
        font-size: 14px;
        border-bottom: 1px solid #888;
        span{
          .icon-arrow{
            margin: 0 10px;
          }
        }
      }
      .product-item{
        width: 600px;
        font-size: 14px;
        color: #666;
        margin-top: 20px;
      }
    }
  }
</style>
